home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: sfx meat.c
-
- Purpose: This module handles the fade modules folder: setting up
- the two lists based on the initial information, setting
- information of fades.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "Folders.h"
- #include "sfx meat.h"
- #include "sfx install.h"
- #include "sfx gestalt.h"
- #include "sfx lists.h"
- #include "progress.h"
- #include "timing.h"
- #include "util.h"
- #include "file interface.h"
-
- struct QDGlobals
- {
- char privates[76];
- long randSeed;
- BitMap screenBits;
- Cursor arrow;
- Pattern dkGray;
- Pattern ltGray;
- Pattern gray;
- Pattern black;
- Pattern white;
- GrafPtr thePort;
- long end;
- };
-
- typedef struct QDGlobals QDGlobals;
- typedef pascal short (*FadeProcPtr)(Rect boundsRect, Pattern *thePattern);
-
- long gModuleDirID;
- short gModuleVRefNum;
-
- /* internal procedures for use in sfx meat.c only */
- static OSErr TouchFolder(FSSpec fs);
- static void DoTheDangFade(FadeProcPtr theFade);
-
-
- enum ErrorTypes SetUpLists(ListHandle usedList, ListHandle unusedList)
- {
- CInfoPBRec pb;
- OSErr isHuman;
- Str255 theName;
- long systemDirID;
- short numModules;
- short i;
- Boolean noModules;
-
- isHuman=FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &gModuleVRefNum,
- &systemDirID); /* find system folder */
- if (isHuman!=noErr)
- return kCantFindSystemFolder;
-
- pb.dirInfo.ioCompletion=0L;
- pb.dirInfo.ioNamePtr=MODULE_FOLDER;
- pb.dirInfo.ioVRefNum=gModuleVRefNum;
- pb.dirInfo.ioFDirIndex=0; /* very important */
- pb.dirInfo.ioDrDirID=systemDirID;
- isHuman=PBGetCatInfo(&pb, FALSE); /* get info on "MSG Fades ƒ" folder */
- if (isHuman!=noErr)
- return kCantFindModuleFolder;
-
- gModuleDirID=pb.dirInfo.ioDrDirID;
- numModules=pb.dirInfo.ioDrNmFls;
-
- MyClearAllCells(usedList);
- MyClearAllCells(unusedList);
-
- noModules=TRUE;
-
- for (i=1; i<=numModules; i++)
- {
- pb.hFileInfo.ioCompletion=0L;
- pb.hFileInfo.ioNamePtr=theName;
- pb.hFileInfo.ioVRefNum=gModuleVRefNum;
- pb.hFileInfo.ioFDirIndex=i;
- pb.hFileInfo.ioDirID=gModuleDirID;
- isHuman=PBGetCatInfo(&pb, FALSE);
- if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
- (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
- {
- /* got a fade module, now find out if it's used or unused and add to list */
-
- if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
- {
- MyAddStr255ToList(usedList, theName);
- noModules=FALSE;
- }
- else if (pb.hFileInfo.ioFlFndrInfo.fdType==UNUSED_TYPE)
- {
- MyAddStr255ToList(unusedList, theName);
- noModules=FALSE;
- }
- }
- }
-
- return noModules ? kNoModulesInFolder : allsWell;
- }
-
- enum ErrorTypes DoTheDemoFade(ListHandle theList)
- {
- Cell theCell;
- Str255 theName;
- Handle theProcHandle;
- FadeProcPtr theFade;
- unsigned long theSize;
- FSSpec fs;
- short oldRefNum, newRefNum;
- Boolean alreadyOpen;
- OSErr theResError;
- Boolean notDoneYet;
-
- if (!MyGetFirstSelectedCell(theList, &theCell))
- return allsWell;
-
- notDoneYet=TRUE;
- while ((LGetSelect(TRUE, &theCell, theList)) && (notDoneYet))
- {
- MyGetCellData(theList, theCell, theName);
- LNextCell(FALSE, TRUE, &theCell, theList);
- MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
- theResError=OpenTheResFile(&fs, &oldRefNum, &newRefNum, &alreadyOpen);
- if (theResError!=noErr)
- return kCantOpenModule;
-
- theProcHandle=Get1Resource('PROC', 0);
- if (((theResError=ResError())!=noErr) || (theProcHandle==0L))
- return kModuleDamaged;
-
- if (*theProcHandle==0L)
- LoadResource(theProcHandle);
- if (*theProcHandle==0L)
- return kModuleDamaged;
-
- theProcHandle=StripAddress(theProcHandle);
- *theProcHandle=StripAddress(*theProcHandle);
-
- HLock(theProcHandle);
- theFade=NewPtrSys(theSize=GetHandleSize(theProcHandle));
- if (theFade==0L)
- {
- ReleaseResource(theProcHandle);
- return kNoMemoryInSystemHeap;
- }
-
- theFade=StripAddress(theFade);
-
- Mymemcpy(theFade, *theProcHandle, theSize);
- ReleaseResource(theProcHandle);
- theProcHandle=0L;
- CloseTheResFile(oldRefNum, newRefNum, alreadyOpen);
- DoTheDangFade(theFade);
- DisposePtr(theFade);
- theFade=0L;
- notDoneYet=DealWithOtherPeople();
- }
-
- return allsWell;
- }
-
- void DoTheDangFade(FadeProcPtr theFade)
- {
- short oldMenuBarHeight;
- long oldA5;
- QDGlobals qd; /* our QD globals. */
- GrafPort gp; /* our grafport. */
- GrafPtr savePort;
- short whichWipe;
- THz saveZone;
- unsigned long temp;
-
- GetPort(&savePort);
- oldMenuBarHeight=MBarHeight;
- MBarHeight=0;
- DrawMenuBar();
-
- /* get a value for A5, a structure that mirrors qd globals. */
- oldA5 = SetA5((long)&qd.end);
- InitGraf(&qd.thePort);
- OpenPort(&gp);
-
- HideCursor();
-
- saveZone=GetZone();
- SetZone(SysZone);
-
- theFade(gp.portRect, &qd.black);
-
- SetZone(saveZone);
-
- MBarHeight=oldMenuBarHeight;
- ShowCursor();
- ObscureCursor();
-
- ClosePort(&gp);
- SetA5(oldA5);
- SetPort(savePort);
-
- StartTiming();
- TimeCorrection(10);
-
- DrawMenuBar();
- PaintOne(0L, GetGrayRgn());
- PaintBehind(WindowList, GetGrayRgn());
- }
-
- enum ErrorTypes DoTheInstall(WindowDataHandle theData, ListHandle usedList,
- ListHandle unusedList)
- {
- Cell theCell;
- CInfoPBRec pb;
- OSErr isHuman;
- Str255 theName;
- GrafPtr curPort;
- FSSpec fs;
-
- if (!MyGetFirstSelectedCell(unusedList, &theCell))
- return allsWell;
-
- while (LGetSelect(TRUE, &theCell, unusedList))
- {
- MyGetCellData(unusedList, theCell, theName);
- LNextCell(FALSE, TRUE, &theCell, unusedList);
- pb.hFileInfo.ioCompletion=0L;
- pb.hFileInfo.ioNamePtr=theName;
- pb.hFileInfo.ioVRefNum=gModuleVRefNum;
- pb.hFileInfo.ioFDirIndex=0;
- pb.hFileInfo.ioDirID=gModuleDirID;
- isHuman=PBGetCatInfo(&pb, FALSE);
- if (isHuman!=noErr)
- return kCantGetModuleInfo;
-
- pb.hFileInfo.ioDirID=gModuleDirID;
- pb.hFileInfo.ioFlFndrInfo.fdType=USED_TYPE;
- isHuman=PBSetCatInfo(&pb, FALSE);
- if (isHuman!=noErr)
- return kCantSetModuleInfo;
- }
-
- MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
- TouchFolder(fs);
-
- LDoDraw(FALSE, usedList);
- LDoDraw(FALSE, unusedList);
- SetUpLists(usedList, unusedList);
- LDoDraw(TRUE, usedList);
- LDoDraw(TRUE, unusedList);
- GetPort(&curPort);
- SetPort((**unusedList).port);
- EraseRect(&((**unusedList).rView));
- SetPort(curPort);
-
- return allsWell;
- }
-
- enum ErrorTypes DoTheRemove(WindowDataHandle theData, ListHandle usedList,
- ListHandle unusedList)
- {
- Cell theCell;
- CInfoPBRec pb;
- OSErr isHuman;
- Str255 theName;
- GrafPtr curPort;
- FSSpec fs;
-
- if (!MyGetFirstSelectedCell(usedList, &theCell))
- return allsWell;
-
- while (LGetSelect(TRUE, &theCell, usedList))
- {
- MyGetCellData(usedList, theCell, theName);
- LNextCell(FALSE, TRUE, &theCell, usedList);
- pb.hFileInfo.ioCompletion=0L;
- pb.hFileInfo.ioNamePtr=theName;
- pb.hFileInfo.ioVRefNum=gModuleVRefNum;
- pb.hFileInfo.ioFDirIndex=0;
- pb.hFileInfo.ioDirID=gModuleDirID;
- isHuman=PBGetCatInfo(&pb, FALSE);
- if (isHuman!=noErr)
- return kCantGetModuleInfo;
-
- pb.hFileInfo.ioDirID=gModuleDirID;
- pb.hFileInfo.ioFlFndrInfo.fdType=UNUSED_TYPE;
- isHuman=PBSetCatInfo(&pb, FALSE);
- if (isHuman!=noErr)
- return kCantSetModuleInfo;
- }
-
- MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
- TouchFolder(fs);
-
- LDoDraw(FALSE, usedList);
- LDoDraw(FALSE, unusedList);
- SetUpLists(usedList, unusedList);
- LDoDraw(TRUE, usedList);
- LDoDraw(TRUE, unusedList);
- GetPort(&curPort);
- SetPort((**usedList).port);
- EraseRect(&((**usedList).rView));
- SetPort(curPort);
-
- return allsWell;
- }
-
- OSErr TouchFolder(FSSpec fs)
- {
- CInfoPBRec pb;
- OSErr isHuman;
-
- pb.dirInfo.ioCompletion=0L;
- pb.dirInfo.ioVRefNum=fs.vRefNum;
- pb.dirInfo.ioDrDirID=fs.parID;
- pb.dirInfo.ioNamePtr=fs.name;
- pb.dirInfo.ioFDirIndex=0;
- if ((isHuman=PBGetCatInfo(&pb, FALSE))!=noErr)
- {
- FlushVol(0L, fs.vRefNum);
- pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID;
- pb.dirInfo.ioFDirIndex=0;
- GetDateTime(&(pb.dirInfo.ioDrMdDat));
- isHuman=PBSetCatInfo(&pb, FALSE);
- FlushVol(0L, fs.vRefNum);
- }
-
- return isHuman;
- }
-